/*
 * Cmeasure.cpp
 *
 *  Created on: Feb 26, 2011
 *      Author: Mo
 */
//#pragma once

#include "tests.h"
#include "experiments.h"
#include "freefuncs.h"
#include "freeformrulebase.h"
#include<string>

#include <time.h>

#include "rbmpgeneratorsync.h"
#include "rbmpgeneratorasync.h"

using namespace std;
//using namespace log4cplus;

//ofstream logFile("GlobalLog.txt");

int main (int argc, char* argv[])
{
	//int a;
	//std::cout << "Attach debugger and enter a number\n";
	//std::cin >> a;

	vector<string> cmdLnP;
	for (int i = 0; i < argc; ++i)
		cmdLnP.push_back(argv[i]);
	char basePath[255] = "";
	_fullpath(basePath, argv[0], sizeof(basePath));
	string exeFullName(basePath);
	unsigned lastSlash = exeFullName.find_last_of("/\\");
	string fullPath = exeFullName.substr(0,lastSlash+1);

	//ex_resolveByNR_AllOrders__Multithread (fullPath + ".\\..\\..\\img\\B1B2-2025\\", fullPath + ".\\..\\..\\txt\\VariableNB_Total_Faces\\2025\\", 1, 128);
	//return SUCCESS;

	//int numberOfOrders = 9;
	//discardingOrder discardingOrderArray[] = {(discardingOrder)0,(discardingOrder)1,(discardingOrder)2,(discardingOrder)3,
	//											(discardingOrder)4,(discardingOrder)5,(discardingOrder)6,(discardingOrder)7,(discardingOrder)8};
	//vector<discardingOrder> vecRemoveOrder (numberOfOrders);
	//std::copy(discardingOrderArray, discardingOrderArray+numberOfOrders, vecRemoveOrder.begin());
	//ex_resolveByNR (vecRemoveOrder, fullPath + ".\\..\\..\\img\\B1B2-2025\\", "", 33, 34);
	//return SUCCESS;

	
	int firstImage;
	int lastImage;
	string inputFolder;
	string outputFolder;

	if (argc > 4)
	{
		firstImage = str2Int(cmdLnP[4]);
		lastImage  = str2Int(cmdLnP[5]);
		inputFolder = fullPath + cmdLnP[2];
		outputFolder = fullPath + cmdLnP[3];
	}

	//if (cmdLnP[1] == "ex_resolveByNR")
	//{
	//	if (argc != 6)
	//		cerr << "Error: 'ex_resolveByNR' takes 4 integer parameters." << endl;
	//	ex_resolveByNR(inputFolder, outputFolder, firstImage, lastImage);
	//	//ex_resolveByNR(cmdLnP[2], cmdLnP[3], firstImage, lastImage);
	//}
	if (cmdLnP[1] == "ex_resolveByNR_AllOrders__Multithread_ParallelOrders")
	{
		if (argc != 6)
			cerr << "Error: 'ex_resolveByNR' takes 4 integer parameters." << endl;
		ex_resolveByNR_AllOrders__Multithread_ParallelOrders(inputFolder, outputFolder, firstImage, lastImage);
	}

	else if (cmdLnP[1] == "ex_resolveByNR_AllOrders__Multithread_ParallelImageSets")
	{
		if (argc != 6)
			cerr << "Error: 'ex_resolveByNR' takes 4 integer parameters." << endl;
		ex_resolveByNR_AllOrders__Multithread_ParallelImageSets(inputFolder, outputFolder, firstImage, lastImage);
	}

	else if (cmdLnP[1] == "ex_resolveBySSRT_Multithread_OneMethod")
	{
		if (argc != 6)
			cerr << "Error: 'ex_resolveByNR' takes 4 integer parameters." << endl;
		ex_resolveBySSRT_Multithread_OneMethod(Rectangle2FormationAlgorithmType::evolution, inputFolder, outputFolder, firstImage, lastImage);
	}

	else if (cmdLnP[1] == "ex_resolveByRBS_Multithread")
	{
		if (argc != 6)
			cerr << "Error: 'ex_resolveByNR' takes 4 integer parameters." << endl;
		ex_resolveByRBS_Multithread(inputFolder, outputFolder, firstImage, lastImage);
	}

	else if (cmdLnP[1] == "ex_resolveByFFRBOnly")
	{
		if (argc != 6)
			cerr << "Error: 'ex_resolveByNR' takes 4 integer parameters." << endl;
		ex_resolveByFFRBOnly(inputFolder, outputFolder, firstImage, lastImage);
	}

	else if (cmdLnP[1] == "ex_resolveBySSRT")
	{
		if (argc != 6)
			cerr << "Error: 'ex_resolveBySSRT' takes 4 integer parameters." << endl;
		ex_resolveBySSRT(Rectangle2FormationAlgorithmType::evolution, inputFolder, outputFolder, firstImage, lastImage);
	}

	else if (cmdLnP[1] == "ex_resolveByRBS")
	{
		if (argc != 6)
			cerr << "Error: 'ex_resolveByRBS' takes 4 integer parameters." << endl;
		ex_resolveByRBS(inputFolder, outputFolder, firstImage, lastImage);
	}

	else
	{
		cout << "Unrecognized command line parameter - Starting Symbiotic EA" << endl;

		ex_SEA (".\\sea");
		srand ( (unsigned int) time(NULL) );
		RBMPGeneratorSync syncGen;
		RBMPGeneratorAsync asyncGen;
		string fileName;
		for (int i = 1; i < 11; ++i)
		{
			syncGen.randomize();
			asyncGen.randomize();
			fileName = "(" + int2Str(i) + ").bmp";
			syncGen.draw(".\\img\\small_test_sync\\" + fileName);
			asyncGen.draw(".\\img\\small_test_Async\\" + fileName);
		}
	}

	return 0;
}
